//
//  HttpTool.swift
//  UseClosure
//
//  Created by liy on 2024/12/19.
//

import UIKit

class HttpTool {
  var callback: ((String) -> Void)?

  func loadData(callback: @escaping (String) -> Void) {
    // 赋值给属性
    self.callback = callback

    DispatchQueue.global().async {
      print("发送请求", Thread.current)

      DispatchQueue.main.async {
        print("返回数据", Thread.current)
        callback("JSON数据")
      }
    }
  }

  func test() {
		//可选绑定使用闭包
    if let callback {
      callback("test")
    }
  }
}
